package com.ruoyi.manage.domain;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;

/**
 * 员工周期性考勤统计对象
 *
 * @author cf
 * @date 2025-06-11
 */
public class AttAttendanceSummary extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 员工ID */
    @Excel(name = "员工ID")
    private Long staffId;

    /** 员工姓名 */
    @Excel(name = "员工姓名")
    private String empName;

    /** 出勤天数 */
    @Excel(name = "正常出勤天数")
    private Integer presentDays;

    /** 迟到次数 */
    @Excel(name = "迟到次数")
    private Integer lateDays;

    /** 早退次数 */
    @Excel(name = "早退次数")
    private Integer earlyLeaveDays;

    /** 缺勤天数 */
    @Excel(name = "缺勤天数")
    private Integer absentDays;

    /** 休假天数 */
    @Excel(name = "休假天数")
    private Integer leaveDays;

    /** 统计周期起始日期 */
    @Excel(name = "周期开始时间", dateFormat = "yyyy-MM-dd")
    private Date periodStart;

    /** 统计周期结束日期 */
    @Excel(name = "周期结束时间", dateFormat = "yyyy-MM-dd")
    private Date periodEnd;

    /** 周期类型（day, week, month, year） */
    @Excel(name = "周期类型")
    private String periodType;

    /** 时间范围字符串（如：2025-06-01 ~ 2025-06-07） */
    private String periodRangeStr;

    /** 周期中文描述（如：2025年第2季度） */
    private String periodDescription;

    /** 考勤评分（假设满分为100分） */
    private Double attendanceScore;

    public Long getStaffId() {
        return staffId;
    }

    public void setStaffId(Long staffId) {
        this.staffId = staffId;
    }

    public String getEmpName() {
        return empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }

    public Integer getPresentDays() {
        return presentDays;
    }

    public void setPresentDays(Integer presentDays) {
        this.presentDays = presentDays;
    }

    public Integer getLateDays() {
        return lateDays;
    }

    public void setLateDays(Integer lateDays) {
        this.lateDays = lateDays;
    }

    public Integer getEarlyLeaveDays() {
        return earlyLeaveDays;
    }

    public void setEarlyLeaveDays(Integer earlyLeaveDays) {
        this.earlyLeaveDays = earlyLeaveDays;
    }

    public Integer getAbsentDays() {
        return absentDays;
    }

    public void setAbsentDays(Integer absentDays) {
        this.absentDays = absentDays;
    }

    public Integer getLeaveDays() {
        return leaveDays;
    }

    public void setLeaveDays(Integer leaveDays) {
        this.leaveDays = leaveDays;
    }

    public Date getPeriodStart() {
        return periodStart;
    }

    public void setPeriodStart(Date periodStart) {
        this.periodStart = periodStart;
    }

    public Date getPeriodEnd() {
        return periodEnd;
    }

    public void setPeriodEnd(Date periodEnd) {
        this.periodEnd = periodEnd;
    }

    public String getPeriodType() {
        return periodType;
    }

    public void setPeriodType(String periodType) {
        this.periodType = periodType;
    }

    public String getPeriodRangeStr() {
        if (periodStart == null || periodEnd == null) return "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(periodStart) + " ~ " + sdf.format(periodEnd);
    }

    public void setPeriodRangeStr(String periodRangeStr) {
        this.periodRangeStr = periodRangeStr;
    }

    public String getPeriodDescription() {
        if (periodStart == null) return "";
        SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(periodStart); // 使用periodStart设置日历
        switch (periodType) {
            case "day":
                return sdfYear.format(periodStart) + "年" + new SimpleDateFormat("MM月dd日").format(periodStart);
            case "week":
                int week = calendar.get(Calendar.WEEK_OF_YEAR); // 获取periodStart对应的周数
                return sdfYear.format(periodStart) + "年第" + week + "周";
            case "month":
                return new SimpleDateFormat("yyyy年MM月").format(periodStart);
            case "quarter":
                int quarter = (Calendar.getInstance().get(Calendar.MONTH) / 3) + 1;
                return sdfYear.format(periodStart) + "年第" + quarter + "季度";
            case "year":
                return sdfYear.format(periodStart) + "年度";
            default:
                return "未知周期";
        }
    }

    public void setPeriodDescription(String periodDescription) {
        this.periodDescription = periodDescription;
    }

    public Double getAttendanceScore() {
        return attendanceScore;
    }

    public void setAttendanceScore(Double attendanceScore) {
        this.attendanceScore = attendanceScore;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("staffId", getStaffId())
                .append("empName", getEmpName())
                .append("presentDays", getPresentDays())
                .append("lateDays", getLateDays())
                .append("earlyLeaveDays", getEarlyLeaveDays())
                .append("absentDays", getAbsentDays())
                .append("leaveDays", getLeaveDays())
                .append("periodStart", getPeriodStart())
                .append("periodEnd", getPeriodEnd())
                .append("periodType", getPeriodType())
                .append("periodRangeStr", getPeriodRangeStr())
                .append("periodDescription", getPeriodDescription())
                .append("attendanceScore", getAttendanceScore())
                .toString();
    }
}
